﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;
using System.IO;

using NUnit.Framework;


namespace Zealib.Extensions
{
    [TestFixture]
    public class StreamExtensionsTest
    {
        [Test]
        public void Test_Stream_SaveAsFile()
        {
            string file = Path.GetTempFileName();
            try
            {
                MemoryStream ms = new MemoryStream();
                byte[] data = new byte[10] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
                ms.Write(data, 0, data.Length);
                ms.Seek(0, SeekOrigin.Begin);
                ms.SaveAsFile(file, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 4096);
                byte[] readData = File.ReadAllBytes(file);
                Assert.AreEqual(data, readData);
            }
            finally
            {
                if (File.Exists(file))
                    File.Delete(file);
            }
        }

    }
}
